Skip to content

Conversation

@rhatdan
Copy link
Member

@rhatdan rhatdan commented Mar 4, 2019

In an effort to remove cross vendoring, trying to fix buildah from importing from
libpod. I believe these libraries make more sense in containers/storage then in libpod.

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

@rhatdan
Copy link
Member Author

rhatdan commented Mar 4, 2019

@giuseppe @nalind PTAL

@rhatdan
Copy link
Member Author

rhatdan commented Mar 4, 2019

@vrothberg PTAL

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit regarding the env variables. We need to be careful with future changes to the package to not introduce regressions.

if (pid)
return pid;

setenv ("_LIBPOD_USERNS_CONFIGURED", "init", 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename the identifiers to CONTAINERS ?

@mheon
Copy link
Member

mheon commented Mar 4, 2019

Why are we moving pkg/util over? That's general-purpose utility functions in Podman

@nalind
Copy link
Member

nalind commented Mar 4, 2019

The util package also depends on github.com/containers/image, which depends on this library.

@rhatdan
Copy link
Member Author

rhatdan commented Mar 4, 2019

@mheon Util package currently is used in buildah, libpod and eventually skopeo.

@rhatdan
Copy link
Member Author

rhatdan commented Mar 4, 2019

Util package also seems mainly concerned with setting up default containers storage.

@rhatdan
Copy link
Member Author

rhatdan commented Mar 4, 2019

@nalind Can we start moving parts of containers image over here if it is needed by both packages.

I would like to get to the point where we have a stack of tools that looks like this. But the vendoring only goes in one direction.

cri-o
libpod
buildah
image
storage

@mheon
Copy link
Member

mheon commented Mar 4, 2019

@rhatdan Not really? There's some storage in there, but that's where I tell people to stick general utility functions, and a fair bit of it will be libpod-specific

@nalind
Copy link
Member

nalind commented Mar 4, 2019

@nalind Can we start moving parts of containers image over here if it is needed by both packages.

The only dependency in that direction so far is a call to manifest.Digest, which we could probably change to a callback or a hook or something.

@rhatdan
Copy link
Member Author

rhatdan commented Mar 4, 2019

@mheon I will remove the parts of utils.go that have nothing to do with storage.

@mheon
Copy link
Member

mheon commented Mar 4, 2019

@rhatdan Ack, SGTM.

I mainly want to keep the package so I can keep telling @baude to put stuff there when nobody knows where to put it

@wking
Copy link
Contributor

wking commented Mar 10, 2019

In an effort to remove cross vendoring, trying to fix buildah from importing from libpod.

I don't have a great handle on how libraries are distributed among these projects, so take this with a grain of salt, but I don't see a connection between the rootless stuff and storage, except for holding a package-level skipStorageSetup boolean. Maybe that package should instead live in buildah and libpod could pull it from there (since libpod already vendors buildah to support podman build)?

@giuseppe
Copy link
Member

I agree with @wking. It might help with vendoring and avoid circular dependencies, but containers/storage doesn't seem the best place for pkg/rootless, it is very libpod centric and the libpod repository still seem like the best place for it.

We are only using a subset of the package from Buildah, we could probably avoid the circular dependency embedding the few changes inside Buildah itself and not requiring pkg/rootless.

@rhatdan rhatdan changed the title Move pkg/rootless and pkg/util from libpod to containers/storage [wip] Move pkg/rootless and pkg/util from libpod to containers/storage Mar 11, 2019
@rhatdan rhatdan force-pushed the rootless branch 5 times, most recently from 5d5054b to 7767c0b Compare March 11, 2019 12:48
@rhatdan
Copy link
Member Author

rhatdan commented Mar 11, 2019

I am moving pkg/rootless to buildah and just putting the StorageDefaults handling in this PR.
@nalind Requested that we pass in the rootless fields, into the storage calls to help it differentiate between the system storage versus rootless storage.

@rhatdan
Copy link
Member Author

rhatdan commented Mar 11, 2019

Opened containers/buildah#1400 to test this patch out and mv pkg/rootless to buildah.

@rhatdan rhatdan changed the title [wip] Move pkg/rootless and pkg/util from libpod to containers/storage Move pkg/rootless and pkg/util from libpod to containers/storage Mar 11, 2019
@rhatdan
Copy link
Member Author

rhatdan commented Mar 11, 2019

@nalind PTAL

}

// GetRootlessRuntimeDir returns the runtime directory when running as non root
func GetRootlessRuntimeDir(rootlessUid int) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used all over libpod.

/home/dwalsh/libpod/libpod/runtime.go:	rootlessRuntimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/runtime.go:		val, err = util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/runtime.go:		runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/runtime.go:		runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()
/home/dwalsh/libpod/libpod/oci.go:	runtimeDir, err := util.GetRootlessRuntimeDir()

}
}
if runtimeDir == "" {
tmpDir := fmt.Sprintf("%s/user/%d", os.TempDir(), rootlessUid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the "user" intermediate directory under what will likely be "/tmp"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it was there in the libpod version. Removed.


// GetRootlessDirInfo returns the parent path of where the storage for containers and
// volumes will be in rootless mode
func GetRootlessDirInfo(rootlessUid int) (string, string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, Fixed

}

// GetRootlessStorageOpts returns the storage opts for containers running as non root
func GetRootlessStorageOpts(rootlessUid int) (storage.StoreOptions, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope Fixed.

}

// GetDefaultStoreOptions returns the default storage ops for containers
func GetDefaultStoreOptions(rootless bool, rootlessUid int) (storage.StoreOptions, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we gain by hiding this in a subpackage? How should a caller know if it should call this function, GetRootlessStorageOpts(), or simply read from storage.DefaultStoreOptions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten again to make these functions primary in storage and to remove links to the constants.
Now storage.DefaultStoreOptions is function.

}

// StorageConfigFile returns the path to the storage config file used
func StorageConfigFile(rootless bool) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should a caller know if this is needed instead of trusting storage.DefaultConfigFile?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make DefaultConfigFile not be exposed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change DefaultConfigFile-> defaultConfigFile.
Now you need to call StorageFile()

// StorageConfigFile returns the path to the storage config file used
func StorageConfigFile(rootless bool) string {
if rootless {
return filepath.Join(os.Getenv("HOME"), ".config/containers/storage.conf")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetRootlessDirInfo() returns an error if $HOME is not set. Should this function be checking for that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@rhatdan rhatdan force-pushed the rootless branch 2 times, most recently from d7908a2 to dcbc3f5 Compare March 12, 2019 14:08
@rhatdan rhatdan changed the title Move pkg/rootless and pkg/util from libpod to containers/storage Move Storage features in pkg/util from libpod to containers/storage Mar 13, 2019
@giuseppe
Copy link
Member

LGTM

utils.go Outdated
if subUIDMap != "" && subGIDMap != "" {
mappings, err := idtools.NewIDMappings(subUIDMap, subGIDMap)
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this with errors.Wrapf.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

utils.go Outdated
}
parsedUIDMap, err := idtools.ParseIDMap(UIDMapSlice, "UID")
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this with errors.Wrapf.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

utils.go Outdated
}
parsedGIDMap, err := idtools.ParseIDMap(GIDMapSlice, "GID")
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this with errors.Wrapf.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

utils.go Outdated

if rootless {
if os.IsNotExist(err) {
os.MkdirAll(filepath.Dir(storageConf), 0755)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for an error here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

if storageOpts.GraphRoot == "" {
storageOpts.GraphRoot = defaultRootlessGraphRoot
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do something about non-nil errors that aren't IsNotExist errors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added handling for this.

@nalind
Copy link
Member

nalind commented Mar 18, 2019

Some nits around error handling, but otherwise LGTM.

@rhatdan rhatdan force-pushed the rootless branch 3 times, most recently from 13662fb to 7157a77 Compare March 18, 2019 16:09
@rhatdan
Copy link
Member Author

rhatdan commented Mar 18, 2019

@giuseppe PTAL I rewrote some of the GetRootlessRuntimeDir functions.

return tmpDir, nil
}
}
tmpDir := fmt.Sprintf("%s/%d", os.TempDir(), rootlessUid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filepath.Join?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That fails to build because rootlessUid is an int.

@giuseppe
Copy link
Member

LGTM

utils.go Outdated
}
parsedUIDMap, err := idtools.ParseIDMap(UIDMapSlice, "UID")
if err != nil {
return nil, errors.Wrapf(err, "failed to create ParseIDMap UID=%s", UIDMapSlice)
Copy link
Member

@TomSweeneyRedHat TomSweeneyRedHat Mar 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to differentiate, could you s/ParseIDMap/ParseUidMap/ here and with ParseGidMap below at line 57?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@TomSweeneyRedHat
Copy link
Member

LGTM other than two small nits.

Test errors are odd. All the go 1.11 tests pass, the others fail due to not being able to find md2man?

Building/Running tests
go get -u -tags " libdm_no_deferred_remove ostree "  github.com/cpuguy83/go-md2man
package github.com/cpuguy83/go-md2man/v2/md2man: cannot find package "github.com/cpuguy83/go-md2man/v2/md2man" in any of:
	/root/.gimme/versions/go1.10.linux.amd64/src/github.com/cpuguy83/go-md2man/v2/md2man (from $GOROOT)
	/root/go/src/github.com/cpuguy83/go-md2man/v2/md2man (from $GOPATH)
Makefile:85: recipe for target 'install.tools' failed
make: *** [install.tools] Error 1
+sudo rm -rf /tmp/storage_iCIjsD

…rage

In an effort to remove cross vendoring, trying to fix buildah from importing
from libpod.  I beleive these libraries make more sense in containers/storage
then in libpod.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@rhatdan rhatdan merged commit dca3d21 into containers:master Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants